/****************************************************
    文件：UIBottomBar.cs
    作者：L.S.Xing
    邮箱: 170105971@qq.com
    日期：#CreateTime#
    功能：
*****************************************************/

using UnityEngine;
using UnityEngine.Events;

namespace LSX
{
    public class UIBottomBar : MonoBehaviour
    {
        public static UIBottomBar Instance;




        // 当前选中 的 索引值
        int currentSelectedIndex;
        // 是否已初始化
        bool inited;

        public UnityAction<int> OnBottomBarItemSelected = delegate { };
        public UnityAction<int> OnBottomBarItemDeselected = delegate { };

        private void Awake()
        {
            Instance = this;
        }

        private void Start()
        {
            // 执行初始化
            SelectBottomBarItem(0);
            // 设置已初始化的值
            inited = true;
        }

        public void SelectBottomBarItem(int index)
        {
            // 如果已经初始化过了
            if (inited)
            {
                // 如果当前点击的index 等于 已激活的index，那么啥都不做
                if (currentSelectedIndex == index)
                    return;
            }

            OnBottomBarItemDeselected?.Invoke(currentSelectedIndex);
            currentSelectedIndex = index;
            OnBottomBarItemSelected?.Invoke(currentSelectedIndex);
        }
    }
}